﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LangRenGameLib.Room
{
    class PlayerInRoom
    {
        /// <summary>
        /// 所处的房间
        /// </summary>
        public Room Owner;

        /// <summary>
        /// 当前房间内的玩家
        /// </summary>
        public List<Player.PlayerInfo> Players;

        /// <summary>
        /// 添加新玩家进入房间
        /// </summary>
        /// <param name="id">玩家ID</param>
        public void AddPlayer(long id, string name = "空")
        {
            Players.Add(new Player.PlayerInfo(id) {
                Name = name,
                InRoom = Owner
            });
        }

        /// <summary>
        /// 从房间内移除玩家
        /// </summary>
        /// <param name="id">玩家ID</param>
        public void ClearPlayer(long id)
        {
            for (int i = 0; i < Players.Count - 1; i++)
            {
                if(Players[i].ID == id)
                {
                    Players.RemoveAt(i);
                    return;
                }
            }
        }
    }
}
